<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <!-- <li class="active">全部</li>
        <li>昌平区</li> -->
        <li :class="{ active: activeFlag == '' }" @click="changeRegion('')">全部</li>
        <li :class="{ active: activeFlag == region.value }" v-for="region in regionArr" :key="region.value"
          @click="changeRegion(region.value)">{{ region.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reqHospitalLevelAndRegion } from '@/api/home/index'
import type { HospitalLevelAndRegionResponseData, HospitalLevelAndRegionArr } from '@/api/home/type'
import { ref, onMounted } from 'vue'
//定义一个数组存储医院等级数据
let regionArr = ref<HospitalLevelAndRegionArr>([]);
//控制医院等级高亮响应式数据
let activeFlag = ref<string>('');
onMounted(() => {
  getRegion()
})
const getRegion = async () => {
  const res: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion('Beijin')
  if (res.code === 200) {
    regionArr.value = res.data
  }

}

const changeRegion = (region: string) => {

  activeFlag.value = region
  emit('getRegion', region)
}
const emit = defineEmits(['getRegion'])
</script>

<script lang="ts">
export default {
  name: "Region",
};
</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 20px;

  .content {
    display: flex;

    .left {
      margin-right: 10px;
      width: 50px;
    }

    ul {
      display: flex;
      flex-wrap: wrap;

      li {
        margin-right: 10px;
        margin-bottom: 10px;

        &.active {
          color: #55a6fe;
        }
      }

      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }

  }
}
</style>
